package ru.tpu.osu.faces.dao;

import java.io.Serializable;
import java.util.List;

import javax.persistence.*;

@Entity
public class Teacher implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 8780841616092587364L;
	@Id
	private String login;
	
	public String getLogin() {
		return login;
	}
	public void setLogin(String login) {
		this.login = login;
	}
	
	@OneToOne(cascade = CascadeType.ALL)
    @PrimaryKeyJoinColumn
	private User user;
	@ManyToOne
	private Title title;
	@ManyToOne
	private Degree degree;
	@ManyToOne
	private Chair chair;
	@OneToMany(mappedBy="author")
	private List<File> files;
	@OneToMany(mappedBy="lecturer")
	private List<Discipline> lectureDisciplines;
	@OneToMany(mappedBy="practiceTeacher")
	private List<Discipline> practiceDisciplines;
	public List<Discipline> getLectureDisciplines() {
		return lectureDisciplines;
	}
	public void setLectureDisciplines(List<Discipline> lectureDisciplines) {
		this.lectureDisciplines = lectureDisciplines;
	}
	public List<Discipline> getPracticeDisciplines() {
		return practiceDisciplines;
	}
	public void setPracticeDisciplines(List<Discipline> practiceDisciplines) {
		this.practiceDisciplines = practiceDisciplines;
	}
	public List<Discipline> getLaboratoryDisciplines() {
		return laboratoryDisciplines;
	}
	public void setLaboratoryDisciplines(List<Discipline> laboratoryDisciplines) {
		this.laboratoryDisciplines = laboratoryDisciplines;
	}

	@OneToMany(mappedBy="laboratoryTeacher")
	private List<Discipline> laboratoryDisciplines;
	
	public List<File> getFiles() {
		return files;
	}
	public void setFiles(List<File> files) {
		this.files = files;
	}
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	public Title getTitle() {
		return title;
	}
	public void setTitle(Title title) {
		this.title = title;
	}
	public Degree getDegree() {
		return degree;
	}
	public void setDegree(Degree degree) {
		this.degree = degree;
	}
	public Chair getChair() {
		return chair;
	}
	public void setChair(Chair chair) {
		this.chair = chair;
	}
	public String getShortName() {
		if (getUser() != null)
			return getUser().getShortName();
		return "";
	}
	public boolean equals(Object other) {
        return other instanceof Teacher  ? getUser().getLogin().equals(((Teacher) other).getUser().getLogin()) : false;
    }
    public int hashCode() {
        return getUser().getLogin().hashCode();
    }
    public String toString() {
		return getShortName();
	}
}
